package org.main.userprovider.controller;

import org.main.bean.POJO.PAddress;
import org.main.bean.POJO.PUser;
import org.main.bean.entity.User;

import org.main.userprovider.Dao.PUserDao;
import org.main.userprovider.Dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/User")
public class UserController {
    @Autowired
    private PUserDao PUserDao;
    @Autowired
    private UserDao userDao;
    @RequestMapping("/query/{id}")
    public PUser getOne(@PathVariable("id") int userId){
        return PUserDao.getOne(userId) ;
    }

    @RequestMapping("/query1")
    public List<PUser>query(){
        return PUserDao.findAll();
    }

    @RequestMapping("/denglu/{name}/{pwd}")
    public  User denglu(@PathVariable("name") String account, @PathVariable("pwd") String userPwd){
        return userDao.denglu(account,userPwd);
    }

    @RequestMapping("/updata/{userId}/{users}/{userName}/{account}/{userPwd}/{userPhone}")
    public String updataUser(@PathVariable("userId") int userId, @PathVariable("users") String users, @PathVariable("userName") String userName, @PathVariable("account") String account, @PathVariable("userPwd") String userPwd, @PathVariable("userPhone") int userPhone){
        String msg ="成功";
        PUser pUser=PUserDao.getOne(userId);
        pUser.setUsers(users);
        pUser.setUserName(userName);
        pUser.setAccount(account);
        pUser.setUserPwd(userPwd);
        pUser.setUserPhone(userPhone);
        try {
            PUserDao.save(pUser);
        } catch (Exception e) {
            msg = "失败";
        }
        return msg;
    }

}
